;Understand, Correct, Improve           ___
;________/| _________________/\__/\____/  /_____
;\  ____/ |/   __/  /  / __ /  \/  \  \  /   __/
;|   __/  /\__   \    /  __ \      /     \  _/ \
;|___\ \__\____  //__/\_____/\    /__/\  /_____/
;+-------------\/breeze'03----\  /crew-\/------+
;                              \/
; Fishb0ne borntro 2008 [Pentagon 1024SL 2.2]
; Copyright (C) 2008 Fishbone CREW All right reserved
; Written by breeze \ fishbone crew | http://twilight.org.ru
; breeze@tut.by
; 29.01.2008

; "Simbol Ninja" old effect from magazine "ZX-Revue"
; New Reincornation in 16 colors ;)

;	in: bc - koords y&x where put simbol,
;	    hl - addr begin sprite of simbol
;
;	ld	bc,(coordsX)		;#4078	; #yyxx, xx - /8
;	call	sibolNinjaUp
;
;	call one phase per int
;	if return a=#ff simbol show complete & can get next simbol

sibolNinjaUp	ld	a,0
		cp	0
		call	z,snInit
		inc	a
		inc	a
		push	hl
		ld	hl,snStored
		cp	(hl)
		jr	z,sibolNinjaUp1
		ld	(sibolNinjaUp+1),a
		jr	sibolNinjaUp2

sibolNinjaUp1	pop	hl
		xor	a
		ld	(sibolNinjaUp+1),a
		ld	(snStored),a		
		ld	a,#ff
		ret						

sibolNinjaUp2	pop	hl
		push	hl
		inc	hl
		ld	(hl),a
		pop	hl


		push	bc
		ld	b,a
		ld	a,(snStored)
		sub	b
		pop	bc
		add	a,b
		ld	b,a

		call	showSpr
		xor	a
		ret


snInit		push	hl,af
		inc	hl
		ld	a,(hl)
		inc	a
		inc	a
		ld	(snStored),a
		pop	af,hl
		ret

;------------------------------------------------
; Draw Sprite
;
;	in: bc - koords y&x where put sprite,
;	    hl - addr begin sprite of sprite

showSpr        	push	hl
		call	xyToScr
		ld	a,h
		push	af
		or	#c0
		ld	h,a
		ld	(addr1+1),hl

		pop	af
		push	af
		or	#40
		ld	h,a
		ld	(addr2+1),hl

		pop	af
		push	af
		or	#e0
		ld	h,a
		ld	(addr3+1),hl

		pop	af
		or	#60
		ld	h,a
		ld	(addr4+1),hl
		
		pop	hl

		ld	a,(hl)
		ld	c,a
		inc	hl
		ld	a,(hl)
		ld	b,a
		inc	hl

loop_1		push	bc
		
addr1		ld	de,#c000
		ld	b,0
		push	de,bc
		ldir	
		pop	bc,de
		call	down_de
		ld	(addr1+1),de
addr2		ld	de,#4000
		push	de,bc
		ldir
		pop	bc,de
		call	down_de
		ld	(addr2+1),de
addr3		ld	de,#e000
		push	de,bc
		ldir
		pop	bc,de
		call	down_de
		ld	(addr3+1),de
addr4		ld	de,#6000
		push	de,bc
		ldir
		pop	bc,de
		call	down_de
		ld	(addr4+1),de
		pop	bc
		djnz	loop_1
		ret

down_de		inc 	d
       		ld 	a,d
       		and 	7
       		ret 	nz
       		ld 	a,e
       		sub 	#e0
       		ld 	e,a
       		ret 	nc
       		ld 	a,d
        	sub 	8
        	ld 	d,a
        	ret

_mul16x8        ld      de,#0000		; умножение HL * A
                ld      (_mul16x8_2+1),de
                cp      0
                jr      nz,_mul16x8_00
                ld      hl,0
                ret

_mul16x8_00     cp	1
		jr	nz,_mul16x8_01
		ld	de,0
		ret

_mul16x8_01	push	bc
		dec	a
		ld	b,a
		ld	c,0
		push	hl
		pop	de
_mul16x8_0	add	hl,de
                jr      nc,_mul16x8_1
                push    de
                ld      de,(_mul16x8_2+1)
                inc     de
                ld      (_mul16x8_2+1),de
                pop     de
_mul16x8_1		djnz	_mul16x8_0
_mul16x8_2      ld      de,#0000
		pop	bc
		ret				; return hl - low, de, high

xyToScr		ld	a,b
		and  	a
		rra
		scf
		rra
		and  	a
		rra
		xor  	b
		and  	#F8
		xor  	b
		and	%10111111	; - #40
		ld   	h,a
		ld   	a,c
		rlca
		rlca
		rlca
		xor  	b
		and  	%11000111	;%11000111	;#C7
		xor  	b
		rlca
		rlca
		ld   	l,a
		ret

snStored	db	0
